'use strict';
const db = uniCloud.database();
const enumCollection = db.collection('xxf-enum');
const dbCmd = db.command;
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event);
	const {
		uid,
		action
	} = event;
	if (!uid && action) {
		return {
			msg: '用户ID参数错误！',
			code: 0,
			data: null
		};
	}
	switch (action) {
		case 'getWaybillCompany':
			return getWaybillCompany(event);
		default:
			return {
				msg: 'Invalid action！',
					code: 0,
					data: null
			};
	}
};
async function getWaybillCompany(params) {
	const {
		uid,
		type,
	} = params;
	const enumRes = await enumCollection.where({
		type,
	}).get();
	console.log("enumRes: ", enumRes);
	if (enumRes.data && enumRes.data.length > 0) {
		return {
			msg: '',
			code: 1,
			data: enumRes.data[0],
		};
	} else {
		return {
			msg: '查询失败！',
			code: 0,
			data: null
		};
	}
}